import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import store from './store'
import {getToken, getUserInfo} from '@/utils/auth'
import {ElMessage} from 'element-plus'


NProgress.configure({showSpinner: false})
let userInfoObj = getUserInfo() ? JSON.parse(getUserInfo()) : {}
let whiteList = [
    '/login',
    '/',
    '/about',
    '/industry',
    '/industryDetail',
    '/banquan',
    '/dsp',
    '/dsp/authorDetail',
    '/dsp/dspDetail',
    '/dsp/zjDetail',
    '/dsp/dspJuBen',
    '/gallery'
]

let checkAuthor = [
    '/creation',
    '/creat',
]

router.beforeEach((to, from, next) => {
    // NProgress.start()
    if (whiteList.indexOf(to.path) > -1) {
        //在白名单之中 允许放行
        next()
    } else {

        if (getUserInfo() == undefined) {
            ElMessage({
                message: '登陆后方可查看',
                type: 'warning',
            })
        } else {
            console.log('人物信息',userInfoObj)
            //  判断是否成为作者
            if (checkAuthor.includes(to.path)) {

                if (userInfoObj.status == 2) {
                    next()
                } else {
                    ElMessage({
                        message: '请先成为作者哦',
                        type: 'warning',
                    })
                    return
                }

            }
            next()
        }

    }


    // if (checkAuthor.indexOf(to.path) > -1) {
    //     if (store.state.userInfo.status != 2) {
    //
    //         ElMessage({
    //             message: '成为作者才可以进入哦',
    //             type: 'warning',
    //         })
    //
    //     } else {
    //         next()
    //     }
    // } else {
    //     next()
    // }

    // NProgress.done()
})

router.afterEach(() => {
    NProgress.done()
})
